export let toplist_detail = {
  namespaced: true,
  state: {
    toplist_detail_data: [],
    official_data: [],
    more_data: [],
    idx_list: {
      "0": "云音乐新歌榜",
      "1": "云音乐热歌榜",
      "2": "网易原创歌曲榜",
      "3": "云音乐飙升榜",
      "4": "云音乐电音榜",
      "5": "UK排行榜周榜",
      "6": "美国Billboard周榜",
      "7": "KTV嗨榜",
      "8": "iTunes榜",
      "9": "Hit FM Top榜",
      "10": "日本Oricon周榜",
      "11": "韩国Melon排行榜周榜",
      "12": "韩国Mnet排行榜周榜",
      "13": "韩国Melon原声周榜",
      "14": "中国TOP排行榜(港台榜)",
      "15": "中国TOP排行榜(内地榜)",
      "16": "香港电台中文歌曲龙虎榜",
      "17": "华语金曲榜",
      "18": "中国嘻哈榜",
      "19": "法国 NRJ EuroHot 30周榜",
      "20": "台湾Hito排行榜",
      "21": "Beatport全球电子舞曲榜",
      "22": "云音乐ACG音乐榜",
      "23": "云音乐嘻哈榜"
    }
  },
  actions: {
    getToplistDetailData(store, data = {}) {
      let url = "/toplist/detail";
      return new Promise((resolve, reject) => {
        axios.get(url).then(({
          data
        }) => {
          let list = store.state.idx_list;
          let filter_data = data.list.filter(item => {
            for (let key in list) {
              if (list.hasOwnProperty(key)) {
                let element = list[key];
                if (item.name == element) {
                  item["idx"] = key;
                  return item;
                }
              }
            }
          });
          let official_data = filter_data.filter(item => item.ToplistType);
          let more_data = filter_data.filter(item => !item.ToplistType);
          store.commit('setToplistDetailData', filter_data);
          store.commit('setOfficialData', official_data);
          store.commit('setMoreData', more_data);
          resolve(data);
        }).catch((error) => {
          if (error.response) {
            // 请求已发出，但服务器响应的状态码不在 2xx 范围内
            reject(error.response.data)
          }
        });
      });
    }
  },
  mutations: {
    setToplistDetailData(state, data = {}) {
      state.toplist_detail_data = data;
    },
    setOfficialData(state, data = {}) {
      state.official_data = data;
    },
    setMoreData(state, data = {}) {
      state.more_data = data;
    },
  }
}
